package de.sendorian.app.forumArchive.renamer;

import de.sendorian.app.forumArchive.domain.File;


public class ForbiddenCharsRenamer implements FileRenamer, StringRenamer {

    public File rename(File file) {
        String name = stripOffForbiddenChars(file.getNameWithoutExtension());
        String ext = file.getExtension();
        file.setName(name + '.' + ext);
        return file;
    }


    public String rename(String name) {
        return stripOffForbiddenChars(name);
    }


    private String stripOffForbiddenChars(String input) {
        String result = input.replaceAll("\\.\\.\\.", "");
        result = result.replaceAll("\\?", "");
        result = result.replaceAll("(:|\\.)", ";");
        result = result.replaceAll("[^\\p{ASCII}]", "");
        return result;
    }
}
